<?php
namespace app\api\controller;

class InsuranceCate extends Permission
{
    public function getList()
    {
        $page = isset($this->input_data['page']) ? $this->input_data['page'] : 1;
        $limit = isset($this->input_data['limit']) ? $this->input_data['limit'] : 1500;
        $map = [];

        $total = db('InsuranceCate')->where($map)->count();
        $rows = db('InsuranceCate')->order('other ASC,id ASC')->page($page,$limit)->where($map)->select();

        
        $list = [];
        foreach ($rows as $v) {
            $list[] = $v;
        }
        
        $data = [
            'total' => $total,
            'list' => $list
        ];
        $this->resSuc($data);
    }

    public function del()
    {

        db('InsuranceCate')->delete( $this->input_data['id']);
        
        $this->resSuc('ok');
    }

    public function update()
    {
        $data['title'] = $this->input_data['title'];

        if($this->input_data['id'] > 0)
        {
            $data['id'] = $this->input_data['id'];
            db('InsuranceCate')->update($data);
        }
        else
        {
            $id = db('InsuranceCate')->insertGetId($data);
        }

        $this->resSuc('success');
    }

    public function getById()
    {
        $map['id'] = $this->input_data['id'];
        $result = db('InsuranceCate')->where($map)->find();
        $this->resSuc($result);
    }

}
